<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>SaveAccount</title>
<link href="UniversalStyleSheet.css" rel="stylesheet" type="text/css" />

</head> 

<body>

<p>
  <%
ContractID=request.Form("Contract_ID")
FirstName=request.Form("firstname")
LastName=request.Form("LastName")
Address=request.Form("address")
city=request.Form("city")
st=request.Form("state")
zip=request.Form("zip")
phone=request.Form("phone")
FromDispatch=request.QueryString("FromDispatch")

dim rs,db
set db=server.CreateObject("adodb.connection")
set rs=server.CreateObject("adodb.recordset")


if ContractID<>"" then 'update existing acct
	
	if isnumeric(left(contractid,1)) then
		table="customers"
		database="homesmart_customers.mdb"
	else
		table="non_homesmart_customers"
		database="tickets.mdb"
	end if
	
	filepath=server.MapPath("\AfterHours\access\BackEnd\" & database)
	db.open "Provider=Microsoft.Jet.OLEDB.4.0;data source=" & filepath
	sql="select * from " & table & " where contract_id='" & ContractID & "';"
	rs.open sql,db, 1,2
	if not rs.eof then
		rs.movefirst
		rs("First_Name")=trim(FirstName)
		rs("Last_Name")=trim(LastName)
		rs("Address")=trim(Address)
		rs("City")=trim(city)
		rs("State")=trim(st)
		rs("Zip")=trim(zip)
		rs("Phone")=trim(phone)
		rs.update
	end if
	rs.close
	savingmessage="Saving Customer Information...</br>Please Wait."
	Redir="customerinformation.asp?ContractID=" & ContractID
else
	filepath=server.MapPath("\AfterHours\access\BackEnd\tickets.mdb")
	db.open "Provider=Microsoft.Jet.OLEDB.4.0;data source=" & filepath
	savingmessage="Creating New Contract ID and Saving New Account"
	sql="select max(nonhs_id)as maxnonhs_id from non_homesmart_customers"
	rs.open sql,db,1,2
	maxID=rs("maxnonhs_id")
	rs.close
	NextContractID="NHS"& maxID+1
	'response.Write("NextContractID=" & NextContractID)
	values=maxid+1 & ",0,'" & NextContractID & "','" & FirstName & "','" & LastName & "','" & Address & "','" & city & "','" & st & "','" & zip & "','" & phone & "'"
	sql="insert into non_homesmart_customers (nonhs_id,Account_Number,Contract_ID,First_Name,Last_Name,Address,City,State,Zip,Phone) values (" & values & ");"
	rs.open sql,db,1,2
	'rs.close
	Redir="customerinformation.asp?ContractID="& NextContractID
end if

db.close
%>
</p>
<table width="99%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="20" height="20" background="Images/TableUpperLeft.png"></td>
    <td height="20" background="Images/TableUpperMiddle.png"></td>
    <td width="20" height="20" background="Images/TableUpperRight.png"></td>
  </tr>
  <tr>
    <td width="20" background="Images/TableMiddleLeft.png"></td>
    <td align="center" valign="middle" bgcolor="#FFFFFF"><%= savingmessage %></td>
    <td width="20" background="Images/TableMiddleRight.png"></td>
  </tr>
  <tr>
    <td width="20" height="20" background="Images/TableLowerLeft.png"></td>
    <td height="20" background="Images/TableLowerMiddle.png"></td>
    <td width="20" height="20" background="Images/TableLowerRight.png"></td>
  </tr>
</table>
<% 
if FromDispatch="yes" then Redir=Redir & "&FromDispatch=yes" 
response.redirect(Redir) %>

</body>
</html>
